import 'dart:math';
import 'dart:ui';

import 'package:flame/components.dart';
import 'package:flame/particles.dart';

class RotationParticle extends CurvedParticle with SingleChildParticle {
  @override
  Particle child;

  final double from;
  final double to;

  RotationParticle({
    required this.child,
    this.from = 0,
    this.to = 2 * pi,
    double? lifespan,
  }) : super(lifespan: lifespan);

  double get angle => lerpDouble(from, to, progress) ?? 0;

  @override
  void render(Canvas canvas) {
    canvas.save();
    canvas.rotate(angle);
    super.render(canvas);
    canvas.restore();
  }
}
